package concurrency.chapter11;

/**
 * @author honway.liu
 * @date 2019-07-04 20:51
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 */
public class AsyncFuture<T> implements Future<T> {

    private volatile boolean done = false;

    private T result;

    public synchronized void done(T result) {
        this.result = result;
        this.done = true;
        this.notifyAll();
    }

    @Override
    public synchronized T get() throws InterruptedException {
        while (!done) {
            this.wait();
        }
        return result;
    }
}
